'''
Created on Apr 19, 2012
TC ID: Ecom_5020
Desc: Kiem thu chuc nang tao nhom nguoi dung
@author: lavang
'''
import unittest
from HTMLTestRunner import HTMLTestRunner
import time
from Functions.loginPageFunc import login
from Functions.globalFunc import readData, preCondition, endCondition
from Functions.userGroupsFunc import clickOnUserGroups, clickOnNewGroup,\
    createUserGroup, isUserGroupCreatedSuccessfully, clickOnLinkUserGroup

username=readData("username")
password=readData("password")
tm_groupName=readData("groupName",index=2)
tm_description=' this is description'
tm_key='group1'
tm_maxKey=2
tm_defaultLearnerType=readData("userType")
class Ecom_5020(unittest.TestCase):


    def setUp(self):
        preCondition(self)

    def test_Ecom_5020(self):
        print "Buoc 1: Dang nhap vao website"
        login(self,username,password)
        
        print "Buoc 2: Click vao User groups"
        clickOnUserGroups(self)
        
        print "Buoc 3: Click vao New Group"
        clickOnNewGroup(self)
        
        print "Buoc 4: Nhap thong tin va tao mot User group"
        createUserGroup(self,tm_groupName,tm_description,tm_key,tm_maxKey,tm_defaultLearnerType)
        
        print "Buoc 5: Tro ve danh sach User group"
        clickOnLinkUserGroup(self)
        
        print "Buoc 6: Xac nhan tao User group thanh cong"
        self.assertTrue(isUserGroupCreatedSuccessfully(self,tm_groupName), "Failed!")
        print "Passed: User group duoc tao thanh cong"
        
    def tearDown(self):
        endCondition(self)



if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    testSuite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Ecom_5020)
    dateTime = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("../../Report/TestResults" + "_" + dateTime + ".html",'wb')
    runner = HTMLTestRunner(
                    stream=buf,
                    title='Test Results',
                    description='Kiem thu chuc nang tao nhom nguoi dung'
                    )
    runner.run(suite)